package codeGenerator;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class JavaFileWriter {

	protected final StringBuffer buffer = new StringBuffer();

	protected FileWriter writer;

	public JavaFileWriter(String anXmlFilename) {
		try {
			this.writer = new FileWriter(new File(anXmlFilename + ".java"));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public String getContents() {
		return this.buffer.toString();
	}

	public void print(String aString) {
		this.buffer.append(aString);
		try {
			this.writer.append(aString);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public void printNewLine() {
		this.print(System.getProperty("line.separator"));
	}

	public void println(String aString) {
		this.print(aString);
		this.printNewLine();
	}

	public void closeStream() {
		try {
			this.writer.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public StringBuffer getBuffer() {
		return buffer;
	}

	public void tab(int anInt) {
		for (int i = 0; i < anInt; i++) {
			this.print("    ");
		}
	}
}
